<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Object 对象 | JavaScript 高级</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.2.0">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
    

        
    
    
    <link rel="next" href="../e9c9c586570ff813bf127694b025d155/3c5d0a2365c2b15c5839ac6e1de9f9ea.html" />
    
    
    <link rel="prev" href="../e9c9c586570ff813bf127694b025d155/f93b5f4ffff4f7cc386af737772af5d5.html" />
    

        
    </head>
    <body>
        
        
    <div class="book" data-level="3.4" data-basepath=".." data-revision="Sat Feb 27 2016 04:15:27 GMT+0800 (CST)">
    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Type to search" class="form-control" />
    </div>
    <ul class="summary">
        
        
        
        

        

        
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        JavaScript 高级
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="449ee81808de646c3a7725ccd403a847/index.html">
            
                
                    <a href="../449ee81808de646c3a7725ccd403a847/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        基本概念复习
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/index.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        面向对象基础
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/6314b9c802f768d42b4c3294598305c0.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/6314b9c802f768d42b4c3294598305c0.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        面向对象的基本概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/39a0b92e978700a4f6f2a2bd2f2d8ba3.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/39a0b92e978700a4f6f2a2bd2f2d8ba3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        JavaScript 中的内置对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/4ed367f57d2b383ff22c531342b042b6.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/4ed367f57d2b383ff22c531342b042b6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        Array 与 Array 常用方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/c16f2c36602b806d34e63671f14b0eda.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/c16f2c36602b806d34e63671f14b0eda.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        Date 与 Date 常用方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/2c65b9b998e9058eda51931c6689a6ec.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/2c65b9b998e9058eda51931c6689a6ec.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        包装对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/da251d0d60d5f878f92d862aaedd8eb4.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/da251d0d60d5f878f92d862aaedd8eb4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        自定义对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/06ce5ce1bf4d31438cdcdc0275a9ea08.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/06ce5ce1bf4d31438cdcdc0275a9ea08.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        对象字面量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/a502d4aea13dea8416d2e3c1849c0d2d.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/a502d4aea13dea8416d2e3c1849c0d2d.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        Error 对象与异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="3ab0320f7a4ed5898fe45b7faccb54fd/bac3b9472b2a4d7d14839e8c74e696ca.html">
            
                
                    <a href="../3ab0320f7a4ed5898fe45b7faccb54fd/bac3b9472b2a4d7d14839e8c74e696ca.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        Math 对象与全局对象
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="e9c9c586570ff813bf127694b025d155/index.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        面向对象进阶
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="e9c9c586570ff813bf127694b025d155/c46418c7328d2a8b05cd6ccedd603f88.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/c46418c7328d2a8b05cd6ccedd603f88.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        面向对象基础复习
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="e9c9c586570ff813bf127694b025d155/40a6014bee4d6724e7aa800253818de5.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/40a6014bee4d6724e7aa800253818de5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        原型的基本概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="e9c9c586570ff813bf127694b025d155/f93b5f4ffff4f7cc386af737772af5d5.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/f93b5f4ffff4f7cc386af737772af5d5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        继承的概念
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="3.4" data-path="e9c9c586570ff813bf127694b025d155/9c3f525ec8bdda16f7618bcb3c936b98.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/9c3f525ec8bdda16f7618bcb3c936b98.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        Object 对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="e9c9c586570ff813bf127694b025d155/3c5d0a2365c2b15c5839ac6e1de9f9ea.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/3c5d0a2365c2b15c5839ac6e1de9f9ea.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        Function 对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="e9c9c586570ff813bf127694b025d155/3db73eb5d8866141920eb0d067ba68c3.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/3db73eb5d8866141920eb0d067ba68c3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        作用域链
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="e9c9c586570ff813bf127694b025d155/7c0fb98a684b27a818b1b546418cb62c.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/7c0fb98a684b27a818b1b546418cb62c.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        闭包的基本概念
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="e9c9c586570ff813bf127694b025d155/bec81e72f2f0c7d6d17bd137036d3286.html">
            
                
                    <a href="../e9c9c586570ff813bf127694b025d155/bec81e72f2f0c7d6d17bd137036d3286.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        getter 与 setter
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="e2bb52a93f2a04d3848c6bc059d4442d/index.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        面向对象高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="e2bb52a93f2a04d3848c6bc059d4442d/5d3938919f20993f4b502f77cb59536f.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/5d3938919f20993f4b502f77cb59536f.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        原型链
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="e2bb52a93f2a04d3848c6bc059d4442d/b8c198488b5b2ca72efdae292161824f.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/b8c198488b5b2ca72efdae292161824f.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        函数的四中调用模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="e2bb52a93f2a04d3848c6bc059d4442d/0f37e1ef8250b257649a6d584bd33fb6.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/0f37e1ef8250b257649a6d584bd33fb6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        对象的创建模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="e2bb52a93f2a04d3848c6bc059d4442d/4fa341af02385d07831cfb4509d5bd20.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/4fa341af02385d07831cfb4509d5bd20.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        继承的方式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="e2bb52a93f2a04d3848c6bc059d4442d/a8d890e0bae896874f9af984daf86a53.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/a8d890e0bae896874f9af984daf86a53.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        闭包案例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="e2bb52a93f2a04d3848c6bc059d4442d/6cc37fe6e9df40a64594e3417c638703.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/6cc37fe6e9df40a64594e3417c638703.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        正则表达式对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="e2bb52a93f2a04d3848c6bc059d4442d/0e3ef80c8612c6c6eb5baa8f397b9494.html">
            
                
                    <a href="../e2bb52a93f2a04d3848c6bc059d4442d/0e3ef80c8612c6c6eb5baa8f397b9494.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        XMLHttpRequest 对象
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="6f394fa9c394d83e6cabd0ac644a8b2d/index.html">
            
                
                    <a href="../6f394fa9c394d83e6cabd0ac644a8b2d/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        封装框架基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6" data-path="86469a999ebfad5a31cc516de283dbd9/index.html">
            
                
                    <a href="../86469a999ebfad5a31cc516de283dbd9/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        封装框架
                    </a>
            
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                Published with GitBook
            </a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Table of Contents"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="Search"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="Font Settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">Serif</button>
        <button type="button" data-font="1" class="button">Sans</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">White</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">Sepia</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">Night</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="Share"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    Share on Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    Share on Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    Share on Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    Share on Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    Share on Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >JavaScript 高级</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="object-%E5%AF%B9%E8%B1%A1">Object &#x5BF9;&#x8C61;</h1>
<p>&#x4E3B;&#x8981;&#x5185;&#x5BB9;:</p>
<ul>
<li><code>Object</code> &#x5BF9;&#x8C61;&#x548C;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x7CFB;</li>
<li><code>Object</code> &#x5BF9;&#x8C61;&#x4E2D;&#x5DF2;&#x7684;&#x65B9;&#x6CD5;</li>
<li>&#x5B57;&#x9762;&#x91CF;&#x7684;&#x7C7B;&#x578B;</li>
<li><code>new</code> &#x7684;&#x542B;&#x4E49;</li>
</ul>
<p>&#x4E0E;&#x5176;&#x4ED6;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00; ( Java, C# ) &#x7C7B;&#x4F3C;, &#x53EF;&#x4EE5;&#x8BF4;, JavaScript &#x4E2D;&#x6240;&#x6709;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x6765;&#x81EA;&#x4E8E; <code>Object</code>. &#x4F46;&#x662F;&#x53C8;&#x4E0D;&#x5B8C;&#x5168;&#x662F;&#x8FD9;&#x6837;. JavaScript &#x662F;&#x5229;&#x7528;&#x539F;&#x578B;&#x6765;&#x5B9E;&#x73B0;&#x7EE7;&#x627F;&#x7684;. &#x4E3A;&#x4E86;&#x5F04;&#x6E05;&#x695A; JavaScript &#x7684;&#x7EE7;&#x627F;&#x7684;&#x672C;&#x8D28;, &#x63A5;&#x4E0B;&#x6765;&#x9996;&#x5148;&#x8BA8;&#x8BBA;&#x4E00;&#x4E0B; <code>Object</code> &#x5BF9;&#x8C61;&#x7684;&#x4E00;&#x4E9B;&#x7EC6;&#x8282;.</p>
<h2 id="object-%E5%AF%B9%E8%B1%A1%E5%92%8C%E5%85%B6%E4%BB%96%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%85%B3%E7%B3%BB">Object &#x5BF9;&#x8C61;&#x548C;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x7CFB;</h2>
<p>&#x8981;&#x8BA8;&#x8BBA; Object &#x5BF9;&#x8C61;&#x4E0E;&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x4E4B;&#x95F4;&#x7684;&#x5173;&#x7CFB;, &#x9996;&#x5148;&#x6765;&#x770B;&#x5BF9;&#x8C61;&#x7684;&#x7C7B;&#x578B;.</p>
<h3 id="typeof-%E8%BF%90%E7%AE%97%E7%AC%A6%E5%92%8C%E5%AF%B9%E8%B1%A1%E7%9A%84%E7%B1%BB%E5%9E%8B">typeof &#x8FD0;&#x7B97;&#x7B26;&#x548C;&#x5BF9;&#x8C61;&#x7684;&#x7C7B;&#x578B;</h3>
<p>&#x5728; JavaScript &#x4E2D;, &#x6570;&#x636E;&#x7C7B;&#x578B;&#x5206;&#x4E3A;&#x57FA;&#x672C;&#x7C7B;&#x578B;&#x548C;&#x590D;&#x5408;&#x7C7B;&#x578B;. &#x57FA;&#x672C;&#x7C7B;&#x578B;&#x90FD;&#x6709;&#x81EA;&#x5DF1;&#x7684;&#x7C7B;&#x578B;&#x540D;, &#x4F46;&#x662F;&#x590D;&#x5408;&#x7C7B;&#x578B;&#x90FD;&#x88AB;&#x63CF;&#x8FF0;&#x4E3A; object. &#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>typeof</code> &#x8FD0;&#x7B97;&#x7B26;&#x52A0;&#x4E00;&#x9A8C;&#x8BC1;.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> <span class="hljs-number">123</span>);            <span class="hljs-comment">// =&gt; number</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> <span class="hljs-number">1.23</span>);           <span class="hljs-comment">// =&gt; number</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> <span class="hljs-literal">true</span>);           <span class="hljs-comment">// =&gt; boolean</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> <span class="hljs-string">&quot;jk&quot;</span>);           <span class="hljs-comment">// =&gt; string</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> []);             <span class="hljs-comment">// =&gt; object</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());     <span class="hljs-comment">// =&gt; object</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> {});             <span class="hljs-comment">// =&gt; object</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> /./);            <span class="hljs-comment">// =&gt; object</span>
</code></pre>
<p>&#x53EF;&#x89C1; JavaScript &#x4E2D;&#x5C06;&#x5BF9;&#x8C61;&#x90FD;&#x5F53;&#x505A; object &#x6765;&#x5BF9;&#x5F85;. &#x5176;&#x5B9E;&#x8FD9;&#x4E5F;&#x662F;&#x6709;&#x539F;&#x56E0;&#x7684;. &#x5728; JavaScript &#x4E2D;&#x6240;&#x6709;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x5305;&#x542B; <code>toString()</code>, <code>valueOf()</code> &#x7B49;&#x65B9;&#x6CD5;, &#x5B9E;&#x9645;&#x4E0A;&#x8FD9;&#x4E9B;&#x65B9;&#x6CD5;&#x90FD;&#x6765;&#x6E90;&#x4E8E; <code>Object</code>, &#x4E25;&#x683C;&#x4E0A;&#x8BB2;&#x662F; <code>Object</code> &#x7684;&#x539F;&#x578B; <code>Object.prototype</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// &#x6709;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x6240;&#x6709;&#x4E3A; true</span>
<span class="hljs-built_in">console</span>.log(!![].toString); <span class="hljs-comment">// =&gt; true</span>
<span class="hljs-built_in">console</span>.log(!!(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>).valueOf); <span class="hljs-comment">// =&gt; true</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MyCtr</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-built_in">console</span>.log(!!(<span class="hljs-keyword">new</span> MyCtr).hasOwnProperty); <span class="hljs-comment">// =&gt; true</span>
<span class="hljs-comment">// &#x4E0D;&#x5305;&#x542B;&#x624D;&#x8FD4;&#x56DE; false</span>
<span class="hljs-built_in">console</span>.log(!!{}.jkMethod); <span class="hljs-comment">// =&gt; false</span>
</code></pre>
<p>&#x539F;&#x56E0;&#x5F88;&#x7B80;&#x5355;, &#x5373;&#x4F7F;&#x4EFB;&#x4F55;&#x5BF9;&#x8C61;&#x90FD;&#x76F4;&#x63A5;&#x6216;&#x95F4;&#x63A5;&#x7684;&#x7EE7;&#x627F;&#x81EA; <code>Object.prototype</code> &#x5BF9;&#x8C61;.</p>
<h3 id="object-%E7%9A%84%E5%8E%9F%E5%9E%8B">Object &#x7684;&#x539F;&#x578B;</h3>
<p>&#x4E86;&#x89E3;&#x5230;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x90FD;&#x76F4;&#x63A5;&#x6216;&#x95F4;&#x63A5;&#x7EE7;&#x627F;&#x81EA; <code>Object.prototype</code> &#x540E;, &#x6211;&#x4EEC;&#x6765;&#x7406;&#x4E00;&#x7406; <code>Object</code> &#x548C; <code>Object.prototype</code> &#x4EE5;&#x53CA; &#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x4E4B;&#x95F4;&#x7684;&#x5173;&#x7CFB;.</p>
<p>&#x9996;&#x5148;&#x6765;&#x770B; Object &#x5BF9;&#x8C61;&#x4E0E; <code>Object.prototype</code> &#x7684;&#x5173;&#x7CFB;.</p>
<h4 id="object-%E5%AF%B9%E8%B1%A1%E4%B8%8E%E5%AE%83%E7%9A%84%E5%8E%9F%E5%9E%8B">Object &#x5BF9;&#x8C61;&#x4E0E;&#x5B83;&#x7684;&#x539F;&#x578B;</h4>
<p>&#x5148;&#x6765;&#x770B;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Object</span>();

_ = <span class="hljs-literal">null</span>; <span class="hljs-comment">// &#x7528;&#x4E8E;&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;&#x8C03;&#x8BD5;</span>
</code></pre>
<p>&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;&#x8FD0;&#x884C;&#x540E;:</p>
<p><img src="../images/Snip20160220_7.png" alt=""></p>
<p>&#x53EF;&#x89C1;&#x7531; <code>Object</code> &#x6784;&#x9020;&#x65B9;&#x6CD5;&#x521B;&#x5EFA;&#x51FA;&#x6765;&#x7684;&#x5BF9;&#x8C61;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x6210;&#x5458;.</p>
<p>&#x90A3;&#x4E9B;&#x5BF9;&#x8C61;&#x90FD;&#x5171;&#x6709;&#x7684;&#x65B9;&#x6CD5;, &#x5B9E;&#x9645;&#x4E0A;&#x90FD;&#x6765;&#x6E90;&#x4E8E; <code>__proto__</code>.</p>
<p><img src="../images/Snip20160220_8.png" alt=""></p>
<p>&#x6682;&#x65F6;&#x4E0D;&#x7BA1;&#x8FD9;&#x4E9B;&#x65B9;&#x6CD5;&#x7684;&#x542B;&#x4E49;. &#x8FD9;&#x91CC; <code>o.__proto__</code> &#x5C31;&#x662F; <code>Object.prototype</code>. &#x56E0;&#x6B64;&#x4ED6;&#x4EEC;&#x4E4B;&#x95F4;&#x7684;&#x5173;&#x7CFB;&#x5C31;&#x5F88;&#x6E05;&#x695A;&#x4E86;.</p>
<p><img src="../images/Snip20160220_9.png" alt=""></p>
<p><em>&#x6CE8;&#x610F;: <code>__proto__</code> &#x5E76;&#x975E;&#x6807;&#x51C6;&#x5C5E;&#x6027;.</em></p>
<h4 id="%E5%85%B6%E4%BB%96%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%8E%9F%E5%9E%8B%E5%92%8C-object-prototype">&#x5176;&#x4ED6;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x548C; <code>Object.prototype</code></h4>
<p>&#x4E86;&#x89E3;&#x4E86; Object &#x5BF9;&#x8C61;&#x4E0E;&#x5176;&#x539F;&#x578B;&#x7684;&#x5173;&#x7CFB;&#x540E;, &#x4E0B;&#x9762;&#x6765;&#x770B;&#x770B;&#x4E00;&#x822C;&#x5BF9;&#x8C61;&#x4E0E;&#x539F;&#x578B;&#x7684;&#x5173;&#x7CFB;, &#x4EE5;&#x53CA;&#x4E00;&#x822C;&#x5BF9;&#x8C61;&#x4E0E; <code>Object.prototype</code> &#x7684;&#x5173;&#x7CFB;.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params"></span>) </span>{
}
Person.prototype.sayHello = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;Hello, I&apos;m JK!&quot;</span>);
};
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> Person();
_ = <span class="hljs-literal">null</span>;
</code></pre>
<p>&#x8FD0;&#x884C;&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;&#x540E;:</p>
<p><img src="../images/Snip20160220_12.png" alt=""></p>
<p>&#x53EF;&#x89C1;&#x5176;&#x7ED3;&#x6784;&#x4E0E; Object &#x5BF9;&#x8C61;&#x548C; <code>Object.prototype</code> &#x7684;&#x7ED3;&#x6784;&#x4E00;&#x6837;. &#x7136;&#x800C;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E5F;&#x662F;&#x6709;&#x539F;&#x578B;&#x7684;, &#x867D;&#x7136;&#x65E0;&#x6CD5;&#x4F7F;&#x7528;&#x6784;&#x9020;&#x65B9;&#x6CD5;, &#x4F46;&#x662F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>__proto__</code> &#x6765;&#x67E5;&#x770B;.</p>
<p><img src="../images/Snip20160220_13.png" alt=""></p>
<p>&#x4ECE;&#x4E2D;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;&#x81EA;&#x5B9A;&#x4E49;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x521B;&#x5EFA;&#x51FA;&#x6765;&#x7684;&#x5BF9;&#x8C61; ( <code>new &lt;&#x6784;&#x9020;&#x65B9;&#x6CD5;&gt;</code> )&#x6709;&#x4E00;&#x4E2A;&#x539F;&#x578B;&#x5BF9;&#x8C61;, &#x5373; <code>&lt;&#x6784;&#x9020;&#x65B9;&#x6CD5;&gt;.prototype</code>. &#x800C;&#x8BE5;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E5F;&#x6709;&#x539F;&#x578B;&#x5BF9;&#x8C61;. &#x6839;&#x636E;&#x56FE;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x662F; Object &#x7C7B;&#x578B;&#x7684;. &#x53EF;&#x89C1;, &#x81EA;&#x5B9A;&#x4E49;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x5C31;&#x662F; <code>Object</code> &#x6784;&#x9020;&#x65B9;&#x6CD5;&#x7684;&#x5B9E;&#x4F8B;.</p>
<p><img src="../images/Snip20160220_15.png" alt=""></p>
<p>&#x4ECE;&#x56FE;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x548C; Object &#x5BF9;&#x8C61;, &#x4EE5;&#x53CA;&#x4E4B;&#x95F4;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x7CFB;.</p>
<h4 id="%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1">&#x5185;&#x7F6E;&#x5BF9;&#x8C61;</h4>
<p>&#x524D;&#x9762;&#x8BA8;&#x8BBA;&#x4E86;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;, &#x63A5;&#x4E0B;&#x6765;&#x770B;&#x770B;&#x5185;&#x7F6E;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x4E5F;&#x590D;&#x5408;&#x8FD9;&#x4E2A;&#x5173;&#x7CFB;.</p>
<p>&#x9996;&#x5148;&#x770B;&#x770B;&#x6570;&#x7EC4;:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [];
_ = <span class="hljs-literal">null</span>;
</code></pre>
<p>&#x8BBE;&#x4E0A;&#x65AD;&#x70B9;&#x540E;&#x8FD0;&#x884C;</p>
<p><img src="../images/Snip20160220_16.png" alt=""></p>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;, &#x4E0E;&#x81EA;&#x5B9A;&#x4E49;&#x5BF9;&#x8C61;&#x4E00;&#x81F4;.</p>
<p>&#x540C;&#x7406;&#x9A8C;&#x8BC1; Date &#x5BF9;&#x8C61;, Error &#x5BF9;&#x8C61;&#x90FD;&#x662F;&#x5982;&#x6B64;. &#x4F46;&#x662F; <code>Math</code> &#x5BF9;&#x8C61;&#x4E0D;&#x540C;. <code>Math</code> &#x672C;&#x8EAB;&#x662F;&#x4E00;&#x4E2A; Object &#x7C7B;&#x578B;&#x7684;&#x5BF9;&#x8C61;.</p>
<h2 id="object-%E5%8E%9F%E5%9E%8B%E4%B8%AD%E5%AE%9A%E4%B9%89%E7%9A%84%E6%96%B9%E6%B3%95">Object &#x539F;&#x578B;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x65B9;&#x6CD5;</h2>
<p>&#x63A5;&#x4E0B;&#x6765;&#x8BA8;&#x8BBA; Object &#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x65B9;&#x6CD5;.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = <span class="hljs-built_in">Object</span>.prototype;
_ = <span class="hljs-literal">null</span>;
</code></pre>
<p>&#x8BBE;&#x5B9A;&#x65AD;&#x70B9;, &#x8C03;&#x8BD5;&#x67E5;&#x770B;</p>
<p><img src="../images/Snip20160221_17.png" alt=""></p>
<p>&#x53EF;&#x89C1;&#x539F;&#x578B;&#x5BF9;&#x8C61;&#x4E2D;&#x5305;&#x542B;&#x7684;&#x90FD;&#x662F;&#x65B9;&#x6CD5;:</p>
<ul>
<li><code>__defineGetter__</code> &#x65B9;&#x6CD5;</li>
<li><code>__defineSetter__</code> &#x65B9;&#x6CD5;</li>
<li><code>__lookupGetter__</code> &#x65B9;&#x6CD5;</li>
<li><code>__lookupSetter__</code> &#x65B9;&#x6CD5;</li>
<li><code>constructor</code> &#x65B9;&#x6CD5;</li>
<li><code>hasOwnProperty</code> &#x65B9;&#x6CD5;</li>
<li><code>isPrototypeOf</code> &#x65B9;&#x6CD5;</li>
<li><code>propertyIsEnumerable</code> &#x65B9;&#x6CD5;</li>
<li><code>toLocaleString</code> &#x65B9;&#x6CD5;</li>
<li><code>toString</code> &#x65B9;&#x6CD5;</li>
<li><code>valueOf</code> &#x65B9;&#x6CD5;</li>
<li><code>get __proto__</code> &#x8BFB;&#x5199;&#x5668;</li>
<li><code>set __proto__</code> &#x8BFB;&#x5199;&#x5668;</li>
</ul>
<p>&#x5728;&#x8FD9;&#x4E9B;&#x65B9;&#x6CD5;&#x4E2D;, &#x5E26;&#x6709;&#x4E24;&#x4E2A;&#x4E0B;&#x5212;&#x7EBF;&#x5F00;&#x5934;&#x548C;&#x4E24;&#x4E2A;&#x4E0B;&#x5212;&#x7EBF;&#x7ED3;&#x5C3E;&#x7684;&#x65B9;&#x6CD5;&#x662F;&#x975E;&#x6807;&#x51C6;&#x65B9;&#x6CD5;. &#x56E0;&#x6B64;&#x5728;&#x90E8;&#x5206;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x53EF;&#x80FD;&#x6CA1;&#x6709;&#x5B9E;&#x73B0;.</p>
<p><strong><code>constructor</code> &#x65B9;&#x6CD5;.</strong> &#x8BE5;&#x65B9;&#x6CD5;&#x5373;&#x6784;&#x9020;&#x65B9;&#x6CD5;. &#x8C03;&#x7528;&#x6784;&#x9020;&#x65B9;&#x6CD5;, &#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;. &#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x5C31;&#x662F;&#x8BE5;&#x5BF9;&#x8C61;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x7684;&#x5F15;&#x7528;.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> Person();
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> p.constructor); <span class="hljs-comment">// =&gt; function</span>
<span class="hljs-built_in">console</span>.log(p.constructor === Person); <span class="hljs-comment">// =&gt; true</span>
</code></pre>
<p><strong><code>hasOwnProperty</code> &#x65B9;&#x6CD5;.</strong> &#x8BE5;&#x65B9;&#x6CD5;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x53C2;&#x6570;, &#x7528;&#x6765;&#x5224;&#x65AD;&#x8BE5;&#x5B57;&#x7B26;&#x4E32;&#x8868;&#x793A;&#x540D;&#x5B57;&#x7684;&#x5C5E;&#x6027;&#x662F;&#x5426;&#x4E3A;&#x975E;&#x7EE7;&#x627F;&#x5C5E;&#x6027;. &#x5982;&#x679C;&#x662F;&#x975E;&#x7EE7;&#x627F;&#x5C5E;&#x6027;, &#x5C31;&#x8FD4;&#x56DE; <code>true</code>, &#x5426;&#x5219;&#x8FD4;&#x56DE; <code>false</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.property1 = <span class="hljs-number">1</span>;
}
Person.prototype.property2 = <span class="hljs-number">2</span>;
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> Person();
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;p.property1 = &quot;</span> +
                p.property1 +
                <span class="hljs-string">&quot;, hasOwnProperty = &quot;</span> +
                p.hasOwnProperty(<span class="hljs-string">&quot;property1&quot;</span>));
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;p.property2 = &quot;</span> +
                p.property2 +
                <span class="hljs-string">&quot;, hasOwnProperty = &quot;</span> +
                p.hasOwnProperty(<span class="hljs-string">&quot;property2&quot;</span>));
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;p.toString = &quot;</span> +
                p.toString +
                <span class="hljs-string">&quot;, hasOwnProperty = &quot;</span> +
                p.hasOwnProperty(<span class="hljs-string">&quot;toString&quot;</span>));
</code></pre>
<p>&#x6267;&#x884C;&#x7ED3;&#x679C;&#x4E3A;</p>
<p><img src="../images/Snip20160221_18.png" alt=""></p>
<p><strong><code>isPrototypeOf</code> &#x65B9;&#x6CD5;.</strong> &#x5982;&#x679C;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x662F;&#x53C2;&#x6570;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x578B;&#x5BF9;&#x8C61;, &#x90A3;&#x4E48;&#x5C31;&#x8FD4;&#x56DE; <code>true</code>, &#x5426;&#x5219;&#x8FD4;&#x56DE; <code>false</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params"></span>) </span>{}
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> Person();
<span class="hljs-built_in">console</span>.log(p.isPrototypeOf(p)); <span class="hljs-comment">// =&gt; false</span>
<span class="hljs-built_in">console</span>.log(Person.prototype.isPrototypeOf(p)); <span class="hljs-comment">// =&gt; true</span>
<span class="hljs-built_in">console</span>.log({}.isPrototypeOf(p)); <span class="hljs-comment">// =&gt; false</span>
</code></pre>
<p><strong><code>propertyIsEnumerable</code> &#x65B9;&#x6CD5;.</strong> &#x8BE5;&#x65B9;&#x6CD5;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x53C2;&#x6570;, &#x5982;&#x679C;&#x8BE5;&#x5B57;&#x7B26;&#x4E32;&#x8868;&#x793A;&#x7684;&#x540D;&#x5B57;&#x662F;&#x5BF9;&#x8C61;&#x7684;&#x81EA;&#x6709;&#x5C5E;&#x6027;, &#x540C;&#x65F6;&#x8BE5;&#x5C5E;&#x6027;&#x53EF;&#x679A;&#x4E3E;, &#x90A3;&#x4E48;&#x65B9;&#x6CD5;&#x5C31;&#x4F1A;&#x8FD4;&#x56DE; <code>true</code>, &#x5426;&#x5219;&#x8FD4;&#x56DE; <code>false</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">this</span>.name = <span class="hljs-string">&quot;jk&quot;</span>;
}
Person.prototype.age = <span class="hljs-number">10</span>;
<span class="hljs-built_in">Object</span>.prototype.gender = <span class="hljs-string">&quot;&#x7537;&quot;</span>;
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> Person();
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> k <span class="hljs-keyword">in</span> p) {
    <span class="hljs-built_in">console</span>.log(k + <span class="hljs-string">&quot;, &quot;</span> + p[k] + <span class="hljs-string">&quot;, &quot;</span> + p.propertyIsEnumerable(k));
}
</code></pre>
<p>&#x6267;&#x884C;&#x7ED3;&#x679C;&#x4E3A;</p>
<p><img src="../images/Snip20160221_20.png" alt=""></p>
<p>&#x5B9E;&#x9645;&#x4E0A;&#x8BE5;&#x65B9;&#x6CD5;&#x4E0E; <code>hasOwnProperty</code> &#x65B9;&#x6CD5;&#x7C7B;&#x4F3C;. &#x5728; JavaScript &#x4E2D;&#x53EA;&#x6709;&#x4E00;&#x4E9B;&#x5185;&#x7F6E;&#x7684;&#x7CFB;&#x7EDF;&#x65B9;&#x6CD5;&#x65E0;&#x6CD5;&#x679A;&#x4E3E;. &#x56E0;&#x6B64;&#x8BE5;&#x65B9;&#x6CD5;&#x51E0;&#x4E4E;&#x603B;&#x662F;&#x8FD4;&#x56DE; <code>true</code>. &#x4F46;&#x662F;&#x5728; ECMAScript 5 &#x4E2D;&#x7ED9;&#x51FA;&#x4E86;&#x8BBE;&#x7F6E;&#x5BF9;&#x8C61;&#x7279;&#x6027;&#x7684;&#x65B9;&#x6CD5;, &#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x679A;&#x4E3E;.</p>
<p><strong><code>toString</code> &#x65B9;&#x6CD5;&#x548C; <code>toLocaleString</code> &#x65B9;&#x6CD5;.</strong> &#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x90FD;&#x662F;&#x5C06;&#x5BF9;&#x8C61;&#x8F6C;&#x6362;&#x6210;&#x5B57;&#x7B26;&#x4E32;. &#x4E0D;&#x540C;&#x7684;&#x662F; <code>toLocaleString</code> &#x662F;&#x8F6C;&#x6362;&#x4E3A;&#x672C;&#x5730;&#x5B57;&#x7B26;&#x4E32;. &#x4E00;&#x822C;&#x5BF9;&#x8C61;&#x4E0E; <code>toString</code> &#x4E00;&#x6837;. &#x4F46;&#x662F;&#x65F6;&#x95F4;&#x7C7B;&#x578B;&#x4E0D;&#x540C;.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>];
<span class="hljs-built_in">console</span>.log(arr.toString());
<span class="hljs-built_in">console</span>.log(arr.toLocaleString());
<span class="hljs-keyword">var</span> now = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>();
<span class="hljs-built_in">console</span>.log(now.toString());
<span class="hljs-built_in">console</span>.log(now.toLocaleString());
</code></pre>
<p>&#x6267;&#x884C;&#x7ED3;&#x679C;&#x4E3A;</p>
<p><img src="../images/Snip20160221_23.png" alt=""></p>
<p><strong><code>valueOf</code> &#x65B9;&#x6CD5;.</strong> &#x5F53;&#x5BF9;&#x8C61;&#x9700;&#x8981;&#x8F6C;&#x6362;&#x4E3A;&#x6570;&#x5B57;&#x7C7B;&#x578B;&#x7684;&#x65F6;&#x5019;&#x5C31;&#x4F1A;&#x8C03;&#x7528;&#x8BE5;&#x65B9;&#x6CD5;. &#x8BE5;&#x65B9;&#x6CD5;&#x4E0E; <code>toString</code> &#x7C7B;&#x4F3C;.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a1 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>];
<span class="hljs-keyword">var</span> a2 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>];
a1.valueOf = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x8C03;&#x7528;&#x4E86; valueOf&quot;</span>);
    <span class="hljs-keyword">return</span> <span class="hljs-number">3</span>;
};
a1.toString = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x8C03;&#x7528;&#x4E86;, toString&quot;</span>);
    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;---&quot;</span>;
};
<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">Number</span>(a1));
<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">Boolean</span>(a1));
<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">String</span>(a1));
<span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">Number</span>(a2));
</code></pre>
<p>&#x6267;&#x884C;&#x7ED3;&#x679C;&#x4E3A;</p>
<p><img src="../images/Snip20160221_24.png" alt=""></p>
<p>&#x81F3;&#x4E8E; <code>get</code> &#x548C; <code>set</code> &#x4EE5;&#x53CA;&#x5E26;&#x6709;&#x4E24;&#x4E2A;&#x4E0B;&#x5212;&#x7EBF;&#x7684;&#x65B9;&#x6CD5;, &#x540E;&#x9762;&#x518D;&#x8BE6;&#x7EC6;&#x8BF4;&#x660E;.</p>
<h2 id="%E5%AD%97%E9%9D%A2%E9%87%8F%E7%9A%84%E7%B1%BB%E5%9E%8B">&#x5B57;&#x9762;&#x91CF;&#x7684;&#x7C7B;&#x578B;</h2>
<p>&#x5728;&#x5B9E;&#x9645;&#x5F00;&#x53D1;&#x4E2D;, &#x7531;&#x4E8E;&#x5B57;&#x9762;&#x91CF;&#x4E0D;&#x9700;&#x8981;&#x5B9A;&#x4E49;&#x6784;&#x9020;&#x65B9;&#x6CD5;, &#x4E5F;&#x4E0D;&#x9700;&#x8981; <code>new</code> &#x7B49;&#x64CD;&#x4F5C;. &#x56E0;&#x6B64;&#x5B57;&#x9762;&#x91CF;&#x7684;&#x6548;&#x7387;&#x4F1A;&#x6BD4;&#x8F83;&#x9AD8;, &#x56E0;&#x6B64;&#x5C3D;&#x91CF;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x7684;&#x5B57;&#x9762;&#x91CF;. &#x4F46;&#x662F;, &#x6CA1;&#x6709;&#x6784;&#x9020;&#x65B9;&#x6CD5;, &#x4E5F;&#x5C31;&#x8868;&#x660E;&#x65E0;&#x6CD5;&#x5B9E;&#x73B0;&#x590D;&#x7528;. &#x56E0;&#x6B64;&#x9009;&#x62E9;&#x9700;&#x8981;&#x6743;&#x8861;.</p>
<p>&#x90A3;&#x4E48;&#x5B57;&#x9762;&#x91CF;&#x7684;&#x7C7B;&#x578B;&#x662F;&#x4EC0;&#x4E48;&#x5462;? &#x8FD8;&#x662F;&#x5229;&#x7528;&#x8C03;&#x8BD5;&#x6765;&#x8FDB;&#x884C;&#x67E5;&#x770B;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> o = {};
_ = <span class="hljs-literal">null</span>;
</code></pre>
<p>&#x8BBE;&#x65AD;&#x70B9;&#x540E;:</p>
<p><img src="../images/Snip20160221_26.png" alt=""></p>
<p>&#x53EF;&#x89C1;&#x5BF9;&#x8C61;&#x7684;&#x5B57;&#x9762;&#x91CF;&#x662F; Object &#x7C7B;&#x578B;&#x7684;. &#x5B83;&#x7684;&#x539F;&#x578B;&#x5C31;&#x662F; <code>Object.prototype</code>.</p>
<h2 id="new-%E4%BB%A5%E5%8F%8A%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E7%9A%84%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B">new &#x4EE5;&#x53CA;&#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x6267;&#x884C;&#x8FC7;&#x7A0B;</h2>
<p>&#x9664;&#x4E86;&#x5B57;&#x9762;&#x91CF;&#x4EE5;&#x5916;, &#x5BF9;&#x8C61;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>new</code> &#x6784;&#x9020;&#x51FD;&#x6570;&#x7684;&#x5F62;&#x5F0F;&#x88AB;&#x521B;&#x5EFA;&#x51FA;&#x6765;. &#x4F7F;&#x7528;&#x6784;&#x9020;&#x51FD;&#x6570;&#x4E0E;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x7684;&#x6700;&#x5927;&#x533A;&#x522B;&#x5728;&#x4E8E;, &#x4F7F;&#x7528;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x590D;&#x7528;, &#x5229;&#x7528;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x51FA;&#x591A;&#x4E2A;&#x5BF9;&#x8C61;; &#x4F46;&#x662F;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;&#x7684;&#x5B57;&#x9762;&#x91CF;, &#x53EA;&#x4F1A;&#x6709;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;.</p>
<p>&#x90A3;&#x4E48;&#x6784;&#x9020;&#x51FD;&#x6570;&#x5177;&#x4F53;&#x505A;&#x4E86;&#x4EC0;&#x4E48;, &#x4E0B;&#x9762;&#x6765;&#x8FDB;&#x884C;&#x8BF4;&#x660E;.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Person</span>(<span class="hljs-params">name, age, gender</span>) </span>{
    <span class="hljs-keyword">this</span>.name = name;
    <span class="hljs-keyword">this</span>.age = age;
    tis.gender = gender;
}
<span class="hljs-keyword">var</span> p = <span class="hljs-keyword">new</span> Person(<span class="hljs-string">&quot;jk&quot;</span>, <span class="hljs-number">19</span>, <span class="hljs-string">&quot;m&quot;</span>);
</code></pre>
<p>&#x8FD9;&#x91CC;&#x5B9A;&#x4E49;&#x4E86;&#x6784;&#x9020;&#x51FD;&#x6570; <code>Person</code>, &#x7136;&#x540E;&#x8C03;&#x7528;&#x6784;&#x9020;&#x65B9;&#x6CD5;, &#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61; <code>p</code>.</p>
<p>&#x4EE3;&#x7801; <code>var p = new Person(&quot;jk&quot;, 19, &quot;m&quot;);</code> &#x53EF;&#x4EE5;&#x5206;&#x6210;&#x4E09;&#x4E2A;&#x6B65;&#x9AA4;:</p>
<ul>
<li>&#x6267;&#x884C; <code>new</code> &#x5173;&#x952E;&#x5B57;, &#x5F00;&#x8F9F;&#x5185;&#x5B58;&#x63A7;&#x4EF6;, &#x95ED;&#x5173;&#x83B7;&#x5F97;&#x5185;&#x5B58;&#x5F15;&#x7528;</li>
<li>&#x8C03;&#x7528;&#x6784;&#x9020;&#x65B9;&#x6CD5; <code>Person</code>, &#x4F20;&#x9012;&#x53C2;&#x6570;: <strong>&#x5185;&#x5B58;&#x5F15;&#x7528;</strong>, &#x5B57;&#x7B26;&#x4E32; <code>&quot;jk&quot;</code>, &#x6570;&#x5B57; <code>19</code>, &#x548C;&#x5B57;&#x7B26;&#x4E32; <code>&quot;m&quot;</code> (m &#x8868;&#x793A;&#x7537;, f &#x8868;&#x793A;&#x5973;)</li>
<li>&#x6267;&#x884C;&#x5B8C;&#x6784;&#x9020;&#x65B9;&#x6CD5;, &#x5C06;&#x5730;&#x5740;&#x5F15;&#x7528;&#x8FD4;&#x56DE;&#x7ED9;&#x5DE6;&#x8FB9;&#x7684;&#x53D8;&#x91CF; <code>p</code></li>
</ul>
<h2 id="%E5%B0%8F%E7%BB%93">&#x5C0F;&#x7ED3;</h2>
<ul>
<li>&#x6240;&#x6709;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x7EE7;&#x627F;&#x81EA; <code>Object.prototype</code></li>
<li><code>Object.prototype</code> &#x4E2D;&#x5E38;&#x89C1;&#x7684;&#x65B9;&#x6CD5;&#x6709;:<ul>
<li><code>constructor</code> &#x65B9;&#x6CD5;</li>
<li><code>hasOwnProperty</code> &#x65B9;&#x6CD5;</li>
<li><code>isPrototypeOf</code> &#x65B9;&#x6CD5;</li>
<li><code>propertyIsEnumerable</code> &#x65B9;&#x6CD5;</li>
<li><code>toLocaleString</code> &#x65B9;&#x6CD5;</li>
<li><code>toString</code> &#x65B9;&#x6CD5;</li>
<li><code>valueOf</code> &#x65B9;&#x6CD5;</li>
</ul>
</li>
<li>&#x5BF9;&#x8C61;&#x5B57;&#x9762;&#x91CF;&#x662F; Object &#x7C7B;&#x578B;&#x7684;&#x5BF9;&#x8C61;</li>
<li><code>new</code> &#x5173;&#x952E;&#x5B57;&#x5F00;&#x8F9F;&#x5185;&#x5B58;&#x7A7A;&#x95F4;</li>
<li>&#x6784;&#x9020;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x9690;&#x542B;&#x53C2;&#x6570; <code>this</code></li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../e9c9c586570ff813bf127694b025d155/f93b5f4ffff4f7cc386af737772af5d5.html" class="navigation navigation-prev " aria-label="Previous page: 继承的概念"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../e9c9c586570ff813bf127694b025d155/3c5d0a2365c2b15c5839ac6e1de9f9ea.html" class="navigation navigation-next " aria-label="Next page: Function 对象"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
